﻿using Lanting.Utilities.NetConn;
using LantingConnect.Controller;
using LantingConnect.DBModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Lanting.Utilities.InvokeUIDelegates;

namespace LantingConnect
{
  public  class SEOrderHelper : DbContext//继承DbContext
    {
        #region 数据库方法-根据关键字获取数据-分页
        public void SearchByKey(object _mparams)
        {
            Dictionary<string, string> mparams = _mparams as Dictionary<string, string>;
            string key = mparams["key"];
            int pageIndex = int.Parse(mparams["pageNo"]);
            int pageSize = int.Parse(mparams["pageSize"]);
            Result re = new Result();
            List<SEOrder> datas = new List<SEOrder>();
            var p = new PageModel() { PageIndex = pageIndex, PageSize = pageSize };// 分页查询
            int allCount = 0; //Queryable<student> query2 = db.Queryable<student>();
            if (string.IsNullOrEmpty(key))
            {
                //模糊查询
                datas = seOrderDb.AsQueryable().ToPageList(pageIndex, pageSize, ref allCount);
            }
            else
            {

                datas = seOrderDb.AsQueryable().Where(it => it.FBillNo == key).ToPageList(pageIndex, pageSize, ref allCount);
                if (datas.Count > 0)
                {
                    datas = datas.GetRange(0, 1);
                }
            }
            re.list = datas;
            re.total = allCount;
            if (Controller_Index.Instance.Get_form_index.IsHandleCreated)
            {
                Controller_Index.Instance.Get_form_index.BeginInvoke(
                    new InvokeResultDelegate(Controller_Index.Instance.Get_form_index.Handler_dbGetSEOrderListIMP), re);
            }

        }
        #endregion
    }
}
